/*    创建个人信息对象         */
var person={
    personName: null,
    personImg: null,
    personGender: null,
    personBirthday: null,
    startWorkYear: null,
    personTel: null,
    personJObType: null,
    personEmail: null,
    personLoc: null,
    idCardType: null,
    personId: null,
    personIncome: null//收入
}


//显示更多个人信息
function showmore() {
    var moreInfo=document.querySelector(".info-datil");
    if (moreInfo.style.display=="none"){
        moreInfo.style.display="block";
    } else {
        moreInfo.style.display="none"
    }
}

/*==================修改建立中的个人信息信息============================================*/
$(".save_cust_info").click(function () {
    $(".body-info").show()
    $(".update-body-info").hide()
    updateCustInfo()
})
function updateCustInfo(){
    //1.获得简历Id
    var resumeId = $(".resumeId").val();
    //2.获得表单中的个人信息
    var custName  = $(".custName").val();
    var gender = document.querySelectorAll(".gender")
    for (var i = 0;i<gender.length;i++){
        custGender =(gender.checked == "checked"? 'M':'F')
    }

    var custBirthday = $(".birthday").val();
    var custStartWorkyear = $(".startworkyear").val();
    var custTelno = $(".phone").val();
    var custWorkStatus = $("#work-status option:selected").text(); //求职状态
    var custEmail = $(".email").val();
    var custLocation = $(".loc").val();
    var custPersonId = $(".custId").val();

    //3. ajax 请求

    $.ajax({
        type: "POST",
        url: "/resume/custInfo",
        datatype: "json",
        data:{
            "_method":"PUT",
            "resumeId":resumeId,
            "custName":custName,
            "custGender":custGender,
            "custBirthday":custBirthday,
            "custStartWorkyear":custStartWorkyear,
            "custTelno":custTelno,
            "custWorkStatus":custWorkStatus,
            "custEmail":custEmail,
            "custLocation":custLocation,
            "custPersonId":custPersonId
        },
        success:function (result) {
            console.log(result);

            if (result.status == 1){ //1.修改成功，查询数据成功,2.将返回的呃最新的resume中个人信息 渲染到页面上

                //用户名
                $(".custName-info").text(result.data.other1);
                //工作年限
                var workyear = new Date().getFullYear()- result.data.other2 ;
                //性别
                var gender =  result.data.resumeGender=='M'?'男':'女';
                //年龄
                var age = new Date().getFullYear() - (new Date(result.data.resumeBirth ).getFullYear())+1;
                //出生日期
                var birthday =   getFullDate(result.data.resumeBirth);


                var value = "现居住于" + result.data.resumeLiveCity + " | " + workyear + "年工作经验  |" + gender +
                    age + "岁(" + birthday + ")  |  " + result.data.resumeLeavingWorking;

                $(".main-body-info .at").text(value);
                //邮箱
                $(".email-info").text( result.data.resumeEmail);
                //手机号
                $(".tel-info").text(result.data.resumeTelno);
                //证件号
                $(".custId-info").text(result.data.resumePersonid)

                //更新时间
                var updateTime =  getFullDate(result.data.resumeUpdateTime);
                $(".updatatime").text(updateTime);

            }else{//修改数据失败
                console.log("修改失败");
                console.log(result.data);
            }
        }
    });
}


function getFullDate(ms) {
    var d = new Date(ms)
    var year = d.getFullYear();
    var month = d.getMonth()+1;
    var day = d.getDate()
    return year+"-"+month+"-"+day
}
//============再次点开修改======================================
$(".main-body-info .update-info").click(function () {
    $(".body-info").hide();
    $(".update-body-info").show();

    // $(".user-page").css("background-image", person.personImg);
    $(".custName").text(person.personName);
    $(".birthday").text(person.personBirthday);
    $(".startworkyear").text(person.startWorkYear);
    $(".phone").text(person.personTel);
    $(".email").text(person.personEmail);
    $(".loc").text(person.personLoc);
    $(".card-select").val(person.idCardType);
    $(".custId").text(person.personId);
    // $(".select-type").val(person.personJObType);
    console.log(person.personName);
    console.log(person.personBirthday);
    console.log(person.startWorkYear);
    console.log(person.personTel);
    console.log(person.personEmail);
    console.log(person.personLoc);
    console.log(person.idCardType);
    console.log(person.personId);
})


//关闭修改info
$(".cancel_cust_info").click(function () {
    $(".body-info").show();
    $(".update-body-info").hide();

    /*================     向简历展示中填写个人的基本信息          ======================*/
    var nowTime = new Date()

    $(".custName-info").text(person.personName);
    $(".main-body-info img").css("background-image", person.personImg)

    var workyear = nowTime.getFullYear() - person.startWorkYear;
    var age = nowTime.getFullYear() - person.personBirthday.substring(0, 4);

    //现居住于苏州工业园区 | 1年工作经验 | 男 | 22岁(1997/08/20) | 目前正在找工作

    var value = "现居住于" + person.personLoc + " | " + workyear + "年工作经验  |" + person.personGender +
        age + "岁(" + person.personBirthday + ")  |  " + person.personJObType;

    $(".at").text(value);

    $(".email-info").text(person.personEmail);
    $(".tel-info").text(person.personTel);
    $(".custId-info").text(person.personId)


})


